package com.lemon.tankgame3;

import java.util.Vector;

/**
 * @author 软柠柠吖
 * @date 2022/1/19
 */
public class Tank {// 坦克父类
    private int x;// 坦克的横坐标
    private int y;// 坦克的纵坐标
    private int direct;// 坦克方向 0上 1右 2下 3左
    private int type = 0;
    private int speed = 1;
    private boolean isLive = true;
    boolean up = true;
    boolean right = true;
    boolean down = true;
    boolean left = true;
    int isActive = -1;
    Wall wall = null;
    Vector<Shot> shots = new Vector<>(100);


    public Tank(int x, int y, int direct, int type, Wall wall) {
        this.x = x;
        this.y = y;
        this.direct = direct;
        this.type = type;
        this.wall = wall;
    }

    // 射击
    public void shotTank() {
        if (!isLive) {
            return;
        }
        Shot shot = null;

        // 创建Shot对象, 根据当前Hero对象的位置和方向来创建Shot
        switch (getDirect()) {
            case 0:// 方向朝上
                shot = new Shot(getX() - 1, getY() - 37, 0, getType(), wall);
                break;
            case 1:// 方向朝右
                shot = new Shot(getX() + 37, getY() - 1, 1, getType(), wall);
                break;
            case 2:// 方向朝下
                shot = new Shot(getX() - 1, getY() + 37, 2, getType(), wall);
                break;
            case 3:// 方向朝左
                shot = new Shot(getX() - 37, getY() - 1, 3, getType(), wall);
                break;
            default:
                break;
        }
        // 启动我们的Shot线程
        shots.add(shot);
        new Thread(shot).start();
    }

    // 上右下左移动的方法
    public void moveUp() {

        y -= speed;
    }


    public void moveRight() {
        x += speed;
    }

    public void moveDown() {
        y += speed;
    }

    public void moveLeft() {
        x -= speed;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getDirect() {
        return direct;
    }

    public void setDirect(int direct) {
        this.direct = direct;
    }

    public int getSpeed() {
        return speed;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public boolean isLive() {
        return isLive;
    }

    public void setLive(boolean live) {
        isLive = live;
    }

    public void setSpeed(int speed) {
        if (speed <= 0 || speed > 10) {
            System.out.println("速度范围在1~10之间，默认为1");
            return;
        }
        this.speed = speed;
    }
}
